package cc.lj.internal.coupons.domain.ticket.service;

import cc.lj.internal.api.ordershare.dto.OrderOnlineAPIDTO;
import cc.lj.internal.coupons.domain.ticket.model.vo.TicketBatchDO;
import cc.lj.internal.coupons.domain.ticket.model.vo.TicketMainDO;
import cc.lj.internal.coupons.interfaces.dto.command.UseTicketCheckCommand;

/**
 * 电子券用券验证 抽象 domain service
 * @author liangxifeng
 * @date 2023/6/15 9:45
 */

public abstract class AbstractUseTicketRuleDomainService {

    //责任链中的下一个元素
    private AbstractUseTicketRuleDomainService nextUseTicketRule;

    public void setNextUseTicketRule(AbstractUseTicketRuleDomainService nextUseTicketRule)
    {
        this.nextUseTicketRule = nextUseTicketRule;
    }

    /**
     * 对外调用验证方法
     * @param batchDO 电子券批次DO
     * @param ticketMainDO 电子券主表DO
     * @param ticketCheckCommand 用券验证Command
     * @param orderOnlineAPIDTO 订单表DTO
     */
    public void checkRule(TicketBatchDO batchDO, TicketMainDO ticketMainDO,
                          UseTicketCheckCommand ticketCheckCommand, OrderOnlineAPIDTO orderOnlineAPIDTO) {
        //具体验证规则
        rule(batchDO,ticketMainDO,ticketCheckCommand,orderOnlineAPIDTO);

        //判断下一个责任链
        if(this.nextUseTicketRule != null)
        {
            nextUseTicketRule.checkRule(batchDO,ticketMainDO,ticketCheckCommand,orderOnlineAPIDTO);
        }
    }

    /**
     * 子类需要实现的抽象方法，该方法中写具体的验证规则
     * @param batchDO
     * @param ticketMainDO
     * @param ticketCheckCommand
     * @param orderOnlineAPIDTO
     */
    abstract protected void rule(TicketBatchDO batchDO,TicketMainDO ticketMainDO,
                                 UseTicketCheckCommand ticketCheckCommand,OrderOnlineAPIDTO orderOnlineAPIDTO) ;
}
